Refactor: DevInitData 구조 분리 및 초기화 로직 개선 (#212) #239
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
📌 개요
DevInitData클래스에 포함되어 있던 데이터 초기화 로직을DevInitService로 분리🔨 작업 내용
1.
DevInitData구조 개선ApplicationRunner에서data.sql실행 여부만 판단하도록 단순화DevInitService로 위임DevInitData내 불필요한 repository 및 passwordEncoder 의존성 제거2.
DevInitService신규 생성@Service클래스 생성, 트랜잭션 관리 및 데이터 초기화 담당EntityManager.flush()추가로 중복 insert 방지3. 제약 조건 위반(
DataIntegrityViolationException) 해결Post.updateCategories()호출 시clear()후 DELETE가 flush 되기 전에 INSERT가 수행되어 UNIQUE 제약 위반 발생entityManager.flush()추가하여 DELETE를 즉시 반영하도록 수정4.
PostCategory초기화 누락 방지postCategoryMappings필드를 명시적으로new ArrayList<>()로 초기화🔗 관련 이슈
Closes #{이슈 번호}
📝 참고 사항
✅ 체크리스트